import { observable, action } from 'mobx';
import { ListAdvanced, ListViewPage, SearchAdvanced, RouteLayout } from 'weaver-mobile-page';
import { Tools, Toast, Bubble } from 'weaver-mobile';
import { toJS } from 'mobx';
import * as API from '../../apis/centerApi';
import * as SUPERVISE_API from '../../apis/superviseApi';
import { transQueryParams } from '../../util/common';
import * as EmSDK from '../../util/emSDK'

const getLabel = Tools.getLabel;
const WORKFLOW_CENTER_STORE = 'WORKFLOW_CENTER_STORE';
export class CenterStore {
    @observable isShowLoading = false;
    currentBtn = '';
    constructor() {
        this.changeCheck = this.changeCheck.bind(this);
        this.requestBatchSubmit = this.requestBatchSubmit.bind(this);
        this.doReadIt = this.doReadIt.bind(this);
        this.getPage = this.getPage.bind(this);
        this.saveStore = this.saveStore.bind(this);
        this.setStore = this.setStore.bind(this);
        this.setSignRemark = this.setSignRemark.bind(this);
        this.onSearch = this.onSearch.bind(this);
        this.getData = this.getData.bind(this);
        // this.loadCountInfo = this.loadCountInfo.bind(this);
        this.getTabs = this.getTabs.bind(this);
        this.chageTable = this.chageTable.bind(this);
        this.setNowTab = this.setNowTab.bind(this);
        this.getDefaultTabs = this.getDefaultTabs.bind(this);
    }
    @observable tabs = [];

    tabName = '';
    @observable popSelectKey = '';
    api_return_scopname = "";

    @observable needRemark = false;

    doingStore = new ListAdvanced.Store({ route: '/center/doing', id: 'doing' });
    doneStore = new ListAdvanced.Store({ route: '/center/done', id: 'done' });
    mineStore = new ListAdvanced.Store({ route: '/center/mine', id: 'mine' });
    allStore = new ListAdvanced.Store({ route: '/center/all', id: 'all' });
    attentionStore = new ListAdvanced.Store({ route: '/center/attentionAll', id: 'attentionAll' });

    @observable nowStore = this.doingStore;

    nowScope = 'doing';
    layout = new RouteLayout.Store({ route: '/center/' + this.nowScope, id: 'follow' });
    @observable cordDatas = '';
    @observable totalcount = 0; //{};

    @observable showTab = true;

    canSubmit = false;
    canRead = false;

    @observable canAddWF = true;

    //批示语
    @observable phrasesDatas = [];

    //签字意见
    @observable remark = '';

    retainCondition = 0;

    @observable title = '';

    queryParams = {};

    menuid = -1;

    titleUrl = undefined;

    multisubmitnotinputsign = 0;

    mobilecenter_button_manifestly = 1;//是否启用移动端流程应用按钮明显化

    //流程快速处理
    isOpenContinuationProcess = false;
    //快速处理的列表查询参数
    searchConditionParams = '';
    
    viewScope = {

        Doing: {
            key: 0,
            name: 'doing',
            path: '/center/doing',
            conditionUrl: '/api/workflow/reqlist/doingBaseInfo?viewScope=doing',
            treeUrl: '/api/workflow/reqlist/doingBaseInfo?viewScope=doing',
            dataURl: '/api/workflow/mobile/getListResult?viewScope=doing'
        },
        All: {
            key: 1,
            name: 'all',
            path: '/center/all',
            conditionUrl: '/api/workflow/customQuery/getFixedCondition',
            treeUrl: '/api/workflow/customQuery/getQueryTree?belongPathTree=true',
            dataURl: '/api/workflow/customQuery/getQueryResultKey?viewScope=all'
        },
        Done: {
            key: 2,
            name: 'done',
            path: '/center/done',
            conditionUrl: '/api/workflow/reqlist/doneBaseInfo?viewScope=done',
            treeUrl: '/api/workflow/reqlist/doneBaseInfo?viewScope=done',
            dataURl: '/api/workflow/mobile/getListResult?viewScope=done'
        },
        Mine: {
            key: 3,
            name: 'mine',
            path: '/center/mine',
            conditionUrl: '/api/workflow/reqlist/mineBaseInfo?viewScope=mine',
            treeUrl: '/api/workflow/reqlist/mineBaseInfo?viewScope=mine',
            dataURl: '/api/workflow/mobile/getListResult?viewScope=mine'
        },
        DoneFinish: {
            key: 0,
            name: 'doing',
            path: '/center/doneFinish',
            conditionUrl: '/api/workflow/reqlist/doingBaseInfo?viewScope=doing',
            treeUrl: '/api/workflow/reqlist/doingBaseInfo?viewScope=doing',
            dataURl: '/api/workflow/mobile/getListResult?viewScope=doing'
        },
        FlowCS: {
            key: 0,
            name: 'doing',
            path: '/center/flowCS',
            conditionUrl: '/api/workflow/reqlist/doingBaseInfo?viewScope=doing',
            treeUrl: '/api/workflow/reqlist/doingBaseInfo?viewScope=doing',
            dataURl: '/api/workflow/mobile/getListResult?viewScope=doing'
        },
        Attention: {
            key: 4,
            name: 'attentionAll',
            path: '/center/attentionAll',
            conditionUrl: '/api/workflow/requestAttention/getCondition_post?viewScope=attentionAll',
            treeUrl: '/api/workflow/requestAttention/getTree?viewScope=attentionAll',
            dataURl: '/api/workflow/requestAttention/getSessionkey_get?viewScope=attentionAll'
        },
    };

    @observable nowViewScope = {
        key: 0,
        name: 'doing',
        path: '/center/doing',
        conditionUrl: '/api/workflow/reqlist/doingBaseInfo?viewScope=doing',
        treeUrl: '/api/workflow/reqlist/doingBaseInfo?viewScope=doing',
        dataURl: '/api/workflow/mobile/getListResult?viewScope=doing'
    };



    /**
     * 当前处于的tab页
     */
    @observable nowTab = 0;

    @observable showCheck = false;

    @observable leftTreeValueArray = [];

    /**
    * 气泡受控
    */
    @observable visible = false;

    @observable nowScopeButtons = [];

    @action changeCheck(check) {
        this.showCheck = check;
    }

    @action setNowTab(index) {
        this.nowTab = index;
    }

    @action setState = (params = {}) => {
        Object.keys(params).forEach(key => {
            this[key] = params[key];
        });
        return this;
    };

    /**
      * 请求列表数据的回调函数，得到datakey,并计算总数
      */
    @action
    getDataCallBack = (result) => {
        const { datas = "", sessionkey = "" } = result;
        this.setTotalCount({ dataKey: datas || sessionkey });
        this.isOpenContinuationProcess = result.isOpenContinuationProcess;
    }

    @action("修改提示的总条数")
    setTotalCount = (params) => {
        API.getDataCount(params).then(res => {
            const { count = 0 } = res;
            // if (this.nowViewScope.name == "doing" || this.nowViewScope.name == "flowAll") {
            this.totalcount = count;
            // } else {
            //     this.totalcount = 0;
            // }
        })
    }

    @action requestBatchSubmit(multiSubIds = [], remark = '', belongtoUserids, extDatas = {}, callback) {
        if (this.currentBtn == 'batchSubmit') {//待办模块，批量提交操作
            for (let index = 0; index < multiSubIds.length; index++) {
                let element = multiSubIds[index];
                multiSubIds[index] = element.substring(0, element.indexOf('+'));
            }

            Toast.loading('Loading...');
            API.requestBatchSubmit({
                multiSubIds: multiSubIds.join(","),
                needBatchSubmit: '1',
                remark,
                belongtoUserids: belongtoUserids,
                ...extDatas
            }).then(result => {
                Toast.hide();
                this.onSearch();
                this.remark = "";

                callback && typeof callback == "function" && callback();
            }).catch(err => {
                // console && console.log(err);
            });
        } else if (this.currentBtn == 'batchSupervise') {//批量督办操作
            this.isShowLoading = true;
            SUPERVISE_API.doSupervise({
                requestids: multiSubIds.join(","),
                remark
            }).then(data => {
                this.isShowLoading = false;
                const { result } = data;
                if (result) {
                    Bubble.success(getLabel(387108, "督办成功"), 2);
                    this.onSearch({}, this.currentBtn);
                } else {
                    Bubble.error(getLabel(387109, "督办失败"), 2);
                }
            })
        } else if (this.currentBtn == 'batchAttention') {

        }
    }

    @action doReadIt(params = {}) {//全部已读操作
        Toast.loading('Loading...', 600);
        API.doReadIt({ ...params }).then(result => {
            Toast.hide();
            this.onSearch();
        }).catch(err => {
            console && console.log(err);
        });
    }

    getOtherParams = () => {
        let dataURl_queryParams = transQueryParams(this.nowViewScope.dataURl);
        let otherParams = {};
        if (dataURl_queryParams.viewcondition) {
            otherParams.viewcondition = dataURl_queryParams.viewcondition;
        }
        if (dataURl_queryParams.mobileDimensionScope) {
            otherParams.mobileDimensionScope = dataURl_queryParams.mobileDimensionScope;
        }
        return otherParams;
    }

    //获取快速处理列表查询参数
    setSearchConditionParams = (params) => {
        let dataURl_queryParams = transQueryParams(this.nowViewScope.dataURl);
        dataURl_queryParams = {...dataURl_queryParams, ...params};
        let finalParams = {};

        let deleteParamsRang = ['_ec_ismobile', '_ec_browser', '_ec_os', '_ec_osVersion', '__random__', '_ec_browserVersion']

        Object.keys(dataURl_queryParams).map(v => {
            if(dataURl_queryParams[v] && dataURl_queryParams[v] != '' && deleteParamsRang.indexOf(v) == -1) {
                finalParams[v] = dataURl_queryParams[v];
            }
        })
        this.searchConditionParams = JSON.stringify(finalParams)
    }


    @action
    chageTable(obj) {
        let key = obj.key;
        this.nowScope = obj.name;
        // if (this.api_return_scopname !== "wfCenter" || this.menuid > 0) {
        this.nowViewScope = obj;
        this.nowScopeButtons = this.nowViewScope.centerButtons;
        EmSDK.controlEmTopNav({title:this.nowViewScope.title});

        delete this.queryParams.workflowid;
        delete this.queryParams.workflowtype;
        delete this.queryParams.workflowId;
        delete this.queryParams.workflowType;
        // } else {
        //     switch (obj.path) {
        //         case "doing":
        //             this.nowViewScope = this.viewScope.Doing;
        //             break;
        //         case "all":
        //             this.nowViewScope = this.viewScope.All;
        //             this.canSubmit = false;
        //             break;
        //         case "done":
        //             this.nowViewScope = this.viewScope.Done;
        //             this.canSubmit = false;
        //             break;
        //         case "mine":
        //             this.nowViewScope = this.viewScope.Mine;
        //             this.canSubmit = false;
        //             break;
        //         case "attentionAll":
        //             this.nowViewScope = this.viewScope.Attention;
        //             this.canSubmit = false;
        //             break;
        //         default:
        //             this.nowViewScope = this.viewScope.Doing;
        //             this.canSubmit = true;
        //     }
        // }
        this.needRemark = false;
        this.nowStore.clear();
        this.leftTreeValueArray = [];
        if (this.retainCondition !== 1) {
            let params = this.nowViewScope.name === "all" ? { ...this.queryParams, menuid: this.menuid, belongPathTree: true, viewType: this.nowViewScope.viewType, mobileTabId: this.nowViewScope.mobileTabId } : { ...this.queryParams, menuid: this.menuid, viewType: this.nowViewScope.viewType, mobileTabId: this.nowViewScope.mobileTabId };
            this.setSearchConditionParams(params);
            this.nowStore.getData({
                url: this.nowViewScope.dataURl,
                params: params
            }, this.getDataCallBack);
        }
        if (this.nowStore.searchAdvancedStore) {
            this.nowStore.searchAdvancedStore
                .getData({
                    //url: this.nowViewScope.name === "all" || this.nowViewScope.name === "attentionAll" ? this.nowViewScope.conditionUrl : this.nowViewScope.treeUrl,
                    url: this.nowViewScope.conditionUrl,
                    method: 'POST',
                    params: this.nowViewScope.name === "all" ? { ...this.queryParams, menuid: this.menuid, belongPathTree: true, viewType: this.nowViewScope.viewType, mobileTabId: this.nowViewScope.mobileTabId } : { ...this.queryParams, menuid: this.menuid, viewType: this.nowViewScope.viewType, mobileTabId: this.nowViewScope.mobileTabId }
                })
                .then(form => {
                    // console && console.log(form);
                });
        }

        this.showCheck = false;
        if (this.canSubmit || this.showTab) {
            this.tabName = obj.name;
        }
        return key;
    }

    /**
     * 通过路径获取所处位置
     * @param {当前路径} path 
     */
    @action getPage(path) {
        const { Doing, Done, Mine, All, DoneFinish, FlowCS, Attention } = this.viewScope;
        // console.log(Attention)
        const { searchParams } = this.nowStore;
        let _searchParams = {};
        if (searchParams.requestname) {
            _searchParams = toJS(searchParams); //{requestname:""}
        }
        this.canSubmit = false;
        this.needRemark = false;
        let key = 0;
        switch (path) {
            case (Doing.path || DoneFinish.path || FlowCS.path):
                this.nowStore = this.doingStore;
                key = Doing.key;
                this.nowScope = Doing.name;
                this.nowViewScope = Doing;
                this.title = "";
                break;
            case All.path:
                this.nowStore = this.allStore;
                key = All.key;
                this.nowScope = All.name;
                this.nowViewScope = All;
                break;
            case Done.path:
                this.nowStore = this.doneStore;
                key = Done.key;
                this.nowScope = Done.name;
                this.nowViewScope = Done;
                break;
            case Mine.path:
                this.nowStore = this.mineStore;
                key = Mine.key;
                this.nowScope = Mine.name;
                this.nowViewScope = Mine;
                break;
            case Attention.path:
                this.nowStore = this.attentionStore;
                key = Attention.key;
                this.nowScope = Attention.name;
                this.nowViewScope = Attention;
                break;
            default:
                key = this.nowTab;
                break;
        }
        if (this.nowTab !== key) {
            // console.log(this.nowViewScope.conditionUrl)
            this.nowStore.clear();
            this.leftTreeValueArray = [];
            if (this.retainCondition !== 1) {
                let params = this.nowViewScope.name === "all" ? { ..._searchParams, belongPathTree: true, viewType: this.nowViewScope.viewType, mobileTabId: this.nowViewScope.mobileTabId } : { ..._searchParams, viewType: this.nowViewScope.viewType, mobileTabId: this.nowViewScope.mobileTabId };
                this.setSearchConditionParams(params);
                this.nowStore.getData({
                    url: this.nowViewScope.dataURl,
                    // params: this.nowViewScope.name === "all" ? { ...this.queryParams, ..._searchParams, belongPathTree: true } : { ...this.queryParams, ..._searchParams }
                    params: params
                }, this.getDataCallBack);
            }
            if (_searchParams.requestname) {
                this.nowStore.setState({ searchParams: _searchParams });
            }
            if (this.nowStore.searchAdvancedStore) {
                this.nowStore.searchAdvancedStore
                    .getData({
                        //url: this.nowViewScope.name === "all" || this.nowViewScope.name === "attentionAll" ? this.nowViewScope.conditionUrl : this.nowViewScope.treeUrl,
                        url: this.nowViewScope.conditionUrl,
                        method: 'POST',
                        params: this.nowViewScope.name === "all" ? { belongPathTree: true, ...this.queryParams, viewType: this.nowViewScope.viewType, mobileTabId: this.nowViewScope.mobileTabId } : { ...this.queryParams, viewType: this.nowViewScope.viewType, mobileTabId: this.nowViewScope.mobileTabId }
                    })
                    .then(form => {
                        if (_searchParams.requestname) {
                            _searchParams.requestname = { value: _searchParams.requestname };
                            form.updateFields(_searchParams);
                        }
                    });
            }
            if (this.queryParams.moduleid) {//有moduleid
                this.nowTab = 0;
            } else {
                this.nowTab = key;
            }
            this.showCheck = false;
            this.remark = '';
        }
        return key;
    }

    /**
     * 跳转的时候保存store到window对象中 之后跳转回来再进行读取
     */
    @action saveStore() {
        if (
            this.nowStore.searchAdvancedStore &&
            this.nowStore.searchAdvancedStore.form
        ) {
            Tools.ss.set(
                WORKFLOW_CENTER_STORE,
                toJS(this.nowStore.searchAdvancedStore.form.formData)
            );
        }
    }

    /**
     * 获取数据
     */
    @action getData(searchParams = {}) {
        searchParams.viewType = this.nowViewScope.viewType;
        searchParams.mobileTabId = this.nowViewScope.mobileTabId;
        let params = this.nowViewScope.name === "all" ? { ...this.queryParams, menuid: this.menuid, belongPathTree: true, ...searchParams } : { ...this.queryParams, menuid: this.menuid, ...searchParams }; 
        if (!params.checkId || params.checkId == '') {
            params.checkId = this.currentBtn || '';
        }
        this.setSearchConditionParams(params);
        this.nowStore.getData({
            url: this.nowViewScope.dataURl,
            params: params
        }, this.getDataCallBack);
        window.sessionStorage && sessionStorage.removeItem("__wf__list__retain__retainCondition");
        this.retainCondition = 0;
    }

    /**
     * 取回原来的数据
     */
    @action setStore() {
        let params = Tools.ss.getJSONObj(WORKFLOW_CENTER_STORE) || {};
        this.retainCondition = 0;
        //leftTreeStore
        if (JSON.stringify(params) != "{}") {
            this.nowStore.searchAdvancedStore.form.updateFields(params);
            if (params.requestname.value && params.requestname.value !== '') {
                this.nowStore.setState({
                    searchParams: { requestname: params.requestname.value },
                });
            }
            this.onSearch();
        } else {
            //getSearchAdvancedDataMounted

            // if(left){
            //     this.nowStore.leftTreeStore.valueArray=left;
            // }

            this.getData();
        }
        return this.nowStore.searchAdvancedStore.form;
    }

    /**
     * 搜索
     */
    @action onSearch(status = {}, checkId = '') {
        const {
            searchAdvancedStore,
            listViewStore,
            searchParams,
            leftTreeStore,
        } = this.nowStore;
        // 搜索框等搜索数据
        let params = {};
        // 获取高级搜索参数
        params = { ...this.queryParams, ...toJS(searchParams) };
        if (searchAdvancedStore) {
            const { formParams } = searchAdvancedStore.form;
            //debugger;
            params = { ...this.queryParams, ...toJS(formParams) };
            let workflowtype = this.nowViewScope.name === "all" ? "typeid" : "workflowtype";
            if (params[workflowtype]) {
                this.setState({
                    leftTreeValueArray: [
                        { id: 'type_' + params[workflowtype], name: params[workflowtype + "span"] },
                        // { id: 'type_' + params.workflowid.value[0].id, name: params.workflowid.value[0].name + 'span' },
                    ],
                });
            } else if (params.workflowid) {
                this.setState({
                    leftTreeValueArray: [
                        { id: 'wf_' + params.workflowid, name: params.workflowidspan },
                    ],
                });
            } else if (!params.workflowid && !params[workflowtype]) {
                this.setState({
                    leftTreeValueArray: [],
                });
            }
        }
        // 清除列表数据
		listViewStore.loading = true;
        listViewStore.clearData();
        if (!status.notClearSelectedRowKeys) {
            listViewStore.setState({ selectedRowKeys: [] });
        }
        // 带参数请求列表数据
        params.menuid = this.menuid;
        if (checkId == '') {
            checkId = this.currentBtn;
        }
        params.checkId = checkId;
        params.viewType = this.nowViewScope.viewType;
        params.mobileTabId = this.nowViewScope.mobileTabId;
        this.setSearchConditionParams(params);
        this.nowStore.getData({
            url: this.nowViewScope.dataURl,
            params,
        }, this.getDataCallBack);
    }

    /**
     * 获取签字意见批示语
     */
    @action setSignRemark() {
        API.loadPhrasesDatas().then(d => {
            this.phrasesDatas = d.phrasesDatas;
            this.multisubmitnotinputsign = d.multisubmitnotinputsign;
        });
    }

    /**
     * 获取待办数量
     */
    // @action loadCountInfo(name = '') {
    //     if (this.menuid > 0 && name === '' && this.tabName) {
    //         name = this.tabName;
    //     }
    //     if (this.titleUrl) {
    //         API.loadCountCustomInfo(this.titleUrl, { menuid: this.menuid, name }).then(d => {
    //             this.totalcount = d.totalcount;
    //             this.title = d.title;
    //         });
    //     } else {
    //         API.loadCountInfo({ menuid: this.menuid, name }).then(d => {
    //             this.totalcount = d.totalcount;
    //             this.title = d.title;
    //         });
    //     }

    // }

    setRetainCondition = () => {
        let retainCondition = {
            api_return_scopname: this.api_return_scopname,
            canRead: this.canRead,
            canSubmit: this.canSubmit,
            showTab: this.showTab,
            tabs: this.tabs,
            titleUrl: this.titleUrl,
            nowTab: this.nowTab,
            searchParams: this.nowStore.searchParams,
            nowViewScope: this.nowViewScope,
            queryParams: this.queryParams,
            mobilecenter_button_manifestly: this.mobilecenter_button_manifestly,
            leftTreeValueArray: this.leftTreeValueArray
        }
        if (this.nowStore.searchAdvancedStore && this.nowStore.searchAdvancedStore.form) {
            retainCondition.searchAdvancedStore_formData = this.nowStore.searchAdvancedStore.form.formData;
            retainCondition.searchAdvancedStore_formParams = this.nowStore.searchAdvancedStore.form.formParams;
            retainCondition.searchAdvancedStore_conditions = this.nowStore.searchAdvancedStore.conditions;
        }
        Tools.ss.set('__wf__list__retain__retainCondition', JSON.stringify(retainCondition));
    }

    @action
    getDefaultTabs() {
        this.tabs = [
            { title: getLabel(500431, '待办事宜'), path: 'doing' },
            { title: getLabel(84382, '全部流程'), path: 'all' },
            { title: getLabel(17991, '已办事宜'), path: 'done' },
            { title: getLabel(1210, '我的请求'), path: 'mine' },
            { title: getLabel(503951, '关注事宜'), path: 'attentionAll' },
        ];
    }

    /**
     * 不支持em等返回方式的情况下，是要重新刷新页面的，为了让重刷后页面状况和之前保持一致，在跳页面前把当前页面状况存入了localstorage中，重刷的时候从localstorage中取值
     * 支持emsdk的环境走返回只刷新数据，不会卸载组件
     * @param {* 当前的moduleid} menuid 
     * @param {*url中是否带retainCondition参数} hasRetainCondition//如果有这个参数，说明当前重刷页面是由于钉钉等不支持em返回方法的环境走了刷新，是从新Mount组件,并且初始值从localstorage中取得
     * 
     */
    @action
    getTabs(menuid, hasRetainCondition) {
        if (hasRetainCondition) {
            let retainCondition = Tools.ss.getJSONObj('__wf__list__retain__retainCondition') || {};
            this.api_return_scopname = retainCondition.api_return_scopname;
            this.nowViewScope = retainCondition.nowViewScope;
            this.nowScopeButtons = this.nowViewScope.centerButtons;
            this.mobilecenter_button_manifestly = retainCondition.mobilecenter_button_manifestly;
            this.queryParams = retainCondition.queryParams;
            this.menuid = menuid;
            this.tabs = retainCondition.tabs || [];
            this.showTab = retainCondition.showTab;
            this.canRead = retainCondition.canRead;
            this.canSubmit = retainCondition.canSubmit;
            this.canAddWF = false;
            this.nowTab = retainCondition.nowTab;
            this.titleUrl = retainCondition.titleUrl;
            this.leftTreeValueArray = retainCondition.leftTreeValueArray;
            if (retainCondition.api_return_scopname == "wfCenter") {
                switch (retainCondition.nowTab) {
                    case 0: this.nowStore = this.doingStore; break;
                    case 1: this.nowStore = this.allStore; break;
                    case 2: this.nowStore = this.doneStore; break;
                    case 3: this.nowStore = this.mineStore; break;
                    case 4: this.nowStore = this.attentionStore; break;
                    default: this.nowStore = this.doingStore;
                }
            }
            let searchParams = retainCondition.searchAdvancedStore_formParams || {};
            if (retainCondition.searchAdvancedStore_formData && retainCondition.searchAdvancedStore_formData.requestname && retainCondition.searchAdvancedStore_formData.requestname.value) {
                this.nowStore.searchParams = { requestname: retainCondition.searchAdvancedStore_formData.requestname.value }
            }
            if (retainCondition.api_return_scopname === 'wfCenter') {   //流程中心
                this.canAddWF = true;
                this.getData(searchParams);
                this.wfCenterTabs(retainCondition.searchAdvancedStore_formData);
                EmSDK.controlEmTopNav({title:this.nowViewScope.title});
                return;
            }
            this.getTabsAfterApi(retainCondition.searchAdvancedStore_formData, searchParams);
        } else {
            API.getTabs({ menuid: menuid,resourceid:this.queryParams.resourceid || "" }).then(d => {
                this.api_return_scopname = d.scope;
                this.mobilecenter_button_manifestly = d.mobilecenter_button_manifestly;
                // this.tabs = [
                //     { title: getLabel(500431, '待办事宜'), path: 'doing' },
                //     { title: getLabel(84382, '全部流程'), path: 'all' },
                //     { title: getLabel(17991, '已办事宜'), path: 'done' },
                //     { title: getLabel(1210, '我的请求'), path: 'mine' },
                //     { title: getLabel(503951, '关注事宜'), path: 'attentionAll' },
                // ];----后端不返回tabs则不给默认tab了
                if (d.scope === 'wfCenter') {   //流程中心--不带menuid的走原本的默认数据，带menuid走新的流程中心应用获取自定义tab
                    d.tabs.length >= 1 ? this.tabs = d.tabs : "";
                    if (this.tabs && this.tabs.length > 0) {//更新当前查看tab属性
                        this.nowViewScope = this.tabs[this.nowTab];
                    }
                    EmSDK.controlEmTopNav({title:this.nowViewScope.title});
                    this.nowScopeButtons = this.nowViewScope.centerButtons;
                    this.menuid = menuid;
                    this.canAddWF = true;
                    this.showTab = d.showTab;
                    this.getData();
                    this.wfCenterTabs()
                    return;
                }
                this.menuid = menuid;
                this.canRead = d.canRead;
                this.canSubmit = d.canSubmit;
                this.showTab = d.showTab;
                d.tabs.length >= 1 ? this.tabs = d.tabs : "";
                this.canAddWF = false;
                this.titleUrl = d.titleUrl;
                //在此处区分是待办、已办、我的请求、办结、抄送
                this.getNewStore(d.scope);
                this.getTabsAfterApi();
            });
        }
    }

    getTabsAfterApi = (formData = {}, searchParams = {}) => {
        let name = '';
        if (this.tabs && this.tabs.length > 0) {
            this.nowViewScope = this.tabs[this.nowTab];
            name = this.tabs[this.nowTab].name;
        }
        EmSDK.controlEmTopNav({title:this.nowViewScope.title});
        this.nowScopeButtons = this.nowViewScope.centerButtons;
        this.tabName = name;
        this.getData(searchParams);
        this.wfCenterTabs(formData);
    }

    wfCenterTabs = (formData = {}) => {
        if (this.nowStore.searchAdvancedStore) {
            this.nowStore.searchAdvancedStore
                .getData({
                    //url: this.nowViewScope.name === "all" || this.nowViewScope.name === "attentionAll" ? this.nowViewScope.conditionUrl : this.nowViewScope.treeUrl,
                    url: this.nowViewScope.conditionUrl,
                    method: 'POST',
                    params: this.nowViewScope.name === "all" ? { ...this.queryParams, menuid: this.menuid, belongPathTree: true } : { ...this.queryParams, menuid: this.menuid }
                })
                .then(form => {
                    if (formData)
                        form.updateFields(formData)
                });
        }
    }

    getNewStore = (scope) => {
        let route = '';
        switch (scope) {
            case "doing":
                route = '/center/doing';
                break;
            case "done":
                route = '/center/done';
                break;
            case "mine":
                route = '/center/mine';
                break;
            case "doneFinish":
                route = '/center/doneFinish';
                break;
            case "flowCS":
                route = '/center/flowCS';
                break;
        }
        this.nowStore = new ListAdvanced.Store({ route: route, id: scope });
    }
}
